home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / sauro.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  208 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. extern unsigned char *sauro_videoram2;
  13. extern unsigned char *sauro_colorram2;
  14.  
  15. static int scroll1;
  16. static int scroll2;
  17. static int flipscreen;
  18.  
  19. /***************************************************************************
  20.  
  21.   Convert the color PROMs into a more useable format.
  22.  
  23. ***************************************************************************/
  24. void sauro_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  25. {
  26.     int i;
  27.  
  28.     for (i = 0;i < Machine->drv->total_colors;i++)
  29.     {
  30.         int bit0,bit1,bit2,bit3;
  31.  
  32.  
  33.         bit0 = (color_prom[0] >> 0) & 0x01;
  34.         bit1 = (color_prom[0] >> 1) & 0x01;
  35.         bit2 = (color_prom[0] >> 2) & 0x01;
  36.         bit3 = (color_prom[0] >> 3) & 0x01;
  37.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  38.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  39.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  40.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  41.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  42.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  43.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  44.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  45.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  46.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  47.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  48.  
  49.         color_prom++;
  50.     }
  51. }
  52.  
  53.  
  54.  
  55. WRITE_HANDLER( sauro_scroll1_w )
  56. {
  57.     scroll1 = data;
  58. }
  59.  
  60.  
  61. static int scroll2_map     [8] = {2, 1, 4, 3, 6, 5, 0, 7};
  62. static int scroll2_map_flip[8] = {0, 7, 2, 1, 4, 3, 6, 5};
  63.  
  64. WRITE_HANDLER( sauro_scroll2_w )
  65. {
  66.     int* map = (flipscreen ? scroll2_map_flip : scroll2_map);
  67.  
  68.     scroll2 = (data & 0xf8) | map[data & 7];
  69. }
  70.  
  71. WRITE_HANDLER( sauro_flipscreen_w )
  72. {
  73.     if (flipscreen != data)
  74.     {
  75.         flipscreen = data;
  76.         memset(dirtybuffer, 1, videoram_size);
  77.     }
  78. }
  79.  
  80. /***************************************************************************
  81.  
  82.   Draw the game screen in the given osd_bitmap.
  83.   Do NOT call osd_update_display() from this function, it will be called by
  84.   the main emulation engine.
  85.  
  86. ***************************************************************************/
  87. void sauro_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  88. {
  89.     int offs,code,sx,sy,color,flipx;
  90.  
  91.  
  92.     /* for every character in the backround RAM, check if it has been modified */
  93.     /* since last time and update it accordingly. */
  94.     for (offs = 0; offs < videoram_size; offs ++)
  95.     {
  96.         if (!dirtybuffer[offs]) continue;
  97.  
  98.         dirtybuffer[offs] = 0;
  99.  
  100.         code = videoram[offs] + ((colorram[offs] & 0x07) << 8);
  101.         sx = 8 * (offs / 32);
  102.         sy = 8 * (offs % 32);
  103.         color = (colorram[offs] >> 4) & 0x0f;
  104.  
  105.         flipx = colorram[offs] & 0x08;
  106.  
  107.         if (flipscreen)
  108.         {
  109.             flipx = !flipx;
  110.             sx = 248 - sx;
  111.             sy = 248 - sy;
  112.         }
  113.  
  114.         drawgfx(tmpbitmap,Machine->gfx[1],
  115.                 code,
  116.                 color,
  117.                 flipx,flipscreen,
  118.                 sx,sy,
  119.                 0,TRANSPARENCY_NONE,0);
  120.     }
  121.  
  122.     if (!flipscreen)
  123.     {
  124.         int scroll = -scroll1;
  125.         copyscrollbitmap(bitmap,tmpbitmap,1,&scroll ,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  126.     }
  127.     else
  128.     {
  129.         copyscrollbitmap(bitmap,tmpbitmap,1,&scroll1,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  130.     }
  131.  
  132.  
  133.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  134.     for (offs = 0; offs < videoram_size; offs++)
  135.     {
  136.         code = sauro_videoram2[offs] + ((sauro_colorram2[offs] & 0x07) << 8);
  137.  
  138.         /* Skip spaces */
  139.         if (code == 0x19) continue;
  140.  
  141.         sx = 8 * (offs / 32);
  142.         sy = 8 * (offs % 32);
  143.         color = (sauro_colorram2[offs] >> 4) & 0x0f;
  144.  
  145.         flipx = sauro_colorram2[offs] & 0x08;
  146.  
  147.         sx = (sx - scroll2) & 0xff;
  148.  
  149.         if (flipscreen)
  150.         {
  151.             flipx = !flipx;
  152.             sx = 248 - sx;
  153.             sy = 248 - sy;
  154.         }
  155.  
  156.         drawgfx(bitmap,Machine->gfx[0],
  157.                 code,
  158.                 color,
  159.                 flipx,flipscreen,
  160.                 sx,sy,
  161.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  162.     };
  163.  
  164.     /* Draw the sprites. The order is important for correct priorities */
  165.  
  166.     /* Weird, sprites entries don't start on DWORD boundary */
  167.     for (offs = 3;offs < spriteram_size - 1;offs += 4)
  168.     {
  169.         sy = spriteram[offs];
  170.         if (sy == 0xf8) continue;
  171.  
  172.         code = spriteram[offs+1] + ((spriteram[offs+3] & 0x03) << 8);
  173.         sx = spriteram[offs+2];
  174.         sy = 236 - sy;
  175.         color = (spriteram[offs+3] >> 4) & 0x0f;
  176.  
  177.         /* I'm not really sure how this bit works */
  178.         if (spriteram[offs+3] & 0x08)
  179.         {
  180.             if (sx > 0xc0)
  181.             {
  182.                 /* Sign extend */
  183.                 sx = (signed int)(signed char)sx;
  184.             }
  185.         }
  186.         else
  187.         {
  188.             if (sx < 0x40) continue;
  189.         }
  190.  
  191.         flipx = spriteram[offs+3] & 0x04;
  192.  
  193.         if (flipscreen)
  194.         {
  195.             flipx = !flipx;
  196.             sx = (235 - sx) & 0xff;  /* The &0xff is not 100% percent correct */
  197.             sy = 240 - sy;
  198.         }
  199.  
  200.         drawgfx(bitmap, Machine->gfx[2],
  201.                 code,
  202.                 color,
  203.                 flipx,flipscreen,
  204.                 sx,sy,
  205.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  206.     }
  207. }
  208.